package com.jichangxiu.server.platform.action;

import cn.hutool.core.collection.ListUtil;
import com.jichangxiu.common.annotation.*;
import com.jichangxiu.common.entity.bo.PageData;
import com.jichangxiu.framework.action.BaseAction;
import com.jichangxiu.server.platform.entity.dto.PlatformPostQueryDto;
import com.jichangxiu.server.platform.entity.vo.PlatformPostAddVo;
import com.jichangxiu.server.platform.entity.vo.PlatformPostEditVo;
import com.jichangxiu.server.platform.entity.vo.PlatformPostQueryVo;
import com.jichangxiu.server.platform.service.PlatformPostService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;

/**
 * PlatformPostAction:
 * 平台-岗位管理控制器
 *
 * @author Jcx
 * @create 2023-02-25 22:10
 */
@Slf4j
@Rest("/platform/post")
@Tag(name = "平台-岗位管理控制器")
public class PlatformPostAction extends BaseAction {

    @Resource
    private PlatformPostService platformPostService;

    /**
     * 新增岗位
     *
     * @param platformPostAddVo 角色视图对象
     * @return 是否成功
     */
    @Post("/add")
    @Operation(summary = "平台-新增岗位")
    @PreAuthorize("@ss.hasPermission('platform:post:add')")
    public String add(@RequestBody PlatformPostAddVo platformPostAddVo) {
        return toStr(platformPostService.add(platformPostAddVo));
    }

    /**
     * 多选级联删除岗位
     *
     * @param postIds 岗位ID列表
     * @return 是否成功
     */
    @Delete("/del")
    @Operation(summary = "平台-多选级联删除岗位")
    @PreAuthorize("@ss.hasPermission('platform:post:del')")
    public String del(@RequestBody String[] postIds) {
        return toStr(platformPostService.del(ListUtil.toList(postIds)));
    }

    /**
     * 修改岗位信息
     *
     * @param platformPostEditVo 岗位视图对象
     * @return 是否成功
     */
    @Put("/edit")
    @Operation(summary = "平台-修改岗位信息")
    @PreAuthorize("@ss.hasPermission('platform:post:edit')")
    public String edit(@RequestBody PlatformPostEditVo platformPostEditVo) {
        return toStr(platformPostService.edit(platformPostEditVo));
    }

    /**
     * 根据ID获取岗位详情
     *
     * @param postId 岗位ID
     * @return 岗位详情
     */
    @Get("/info/{postId}")
    @Operation(summary = "平台-根据ID获取岗位详情")
    @PreAuthorize("@ss.hasPermission('platform:post:info')")
    public PlatformPostQueryDto info(@PathVariable("postId") @NotBlank(message = "岗位ID不能为空") String postId) {
        return platformPostService.info(postId);
    }

    /**
     * 分页查询岗位列表
     *
     * @param platformPostQueryVo 岗位视图对象
     * @return 分页岗位列表
     */
    @Get("/pageList")
    @Operation(summary = "平台-分页查询岗位列表")
    @PreAuthorize("@ss.hasPermission('platform:post:pageList')")
    public PageData<PlatformPostQueryDto> pageList(@ParameterObject PlatformPostQueryVo platformPostQueryVo) {
        return platformPostService.pageList(platformPostQueryVo);
    }

}
